﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Model;

/// <summary>
///BasePage 的摘要说明
/// </summary>
public class BasePage : System.Web.UI.Page
{
    protected Access access = new Access();
    protected override void OnPreInit(EventArgs e)
    {
        if (Request.Url.AbsoluteUri.IndexOf("Login") == -1)
        {
            if (CurrentUserInfo == null)
            {
                Response.Redirect(ResolveUrl("~/Login.aspx"));
            }
        }
        base.OnPreInit(e); 
    }

    public string GetURL()
    {
        //return "m.shanghaivive";
        return "122.226.199.116";
    }
   
    #region 下属页面公用方法
    public string GetQeuryString(string para)
    {
        if (Request.QueryString[para] != null) return Request.QueryString[para].ToString();
        else return "";
    }
    public void AlertAndClose(string message)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert(\"" + message + "\");closeDialog();</script>");
    }
    /// <summary>
    /// 在客户端弹出对话框
    /// </summary>
    public void AlertMessage(string message)
    {
        Page.RegisterStartupScript("AlertMessage", "<script language='javascript'>bootbox.alert(\"" + message.Replace("'", "′") + "\");</script>");
    }
    /// <summary>
    /// treeGrid
    /// </summary>
    public void AlertAndCloseAndReloadParend(string message,string parentControlId)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertCloseReload", "<script>alert(\"" + message + "\");closeDialog(); parent.$('#" + parentControlId + "').treegrid(\"reload\");parent.parent.$('#treeMenu').tree(\"reload\");</script>");
    }
    protected void AlertAndCloseAndReloadParendDataGrid(string message, string parentControlId)
    {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertCloseReload", "<script>alert(\"" + message + "\");closeDialog(); parent.$('#" + parentControlId + "').datagrid(\"reload\");</script>");
    }

    /// <summary>
    /// 再客户端显示一条信息，然后转到一个页面
    /// </summary>
    /// <param name="message">显示的信息</param>
    /// <param name="url">转到页面路径</param>
    protected void AlertRedirect(string message, string url)
    {
        Page.RegisterStartupScript("AlertRedirect", "<script language='javascript'>bootbox.alert(\"" + message.Replace("'", "′") + "\");window.navigate('" + url + "');</script>");
    }
    #endregion

    #region 下属页面公用属性
    protected UserInfo CurrentUserInfo
    {
        get
        {
            if (Session["UserInfo"] != null)
            {
                return (UserInfo)Session["UserInfo"];
            }
            else
            {
                //Response.Redirect("Login.aspx");
                return null;
            }
        }
    }

    public string Skin
    {
        get
        {

            return CurrentUserInfo.Skin;
        }
    }
    #endregion
}